import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		nickName: '',
		sex: '',
		avatar: '',
		mid: '',
		openid: '',
		session_key: '',
		token: '',
		hx_pass: '',
		hx_id: '',
		money_now: '',
		type: '',
	},
	mutations: {
		userInfo(userInfo, data) {
			console.log('userInfo========·======',data.gender) 
			userInfo.nickName = data.nickName
			userInfo.sex = data.gender==1?'男':'女'
				userInfo.avatar = data.avatarUrl
				console.log("userinfo1111111111111111",data.gender)
			uni.setStorageSync('userInfo', data)

		},
		getOpenid(getOpenid, data) {
			// if (uni.getStorageSync('loginToken')) {
			// 	uni.removeStorageSync('loginToken')
			// }
			if (data.hx_id && data.hx_pass) {
				getOpenid.hx_id = data.hx_id
				getOpenid.hx_pass = data.hx_pass
				uni.setStorageSync('myUsername', data.hx_id)
			}
			getOpenid.mid = data.mid
			getOpenid.openid = data.openid
			getOpenid.session_key = data.session_key
			getOpenid.token = data.token
			console.log(data.token)
			uni.setStorageSync('getOpenid', data)
			uni.setStorageSync('loginToken', data.token)
		},
		moneyNow(moneyNow, data) {
			moneyNow.money_now = data
			uni.setStorageSync('moneyNow', data)
		},
		mytype(mytype, data) {
			mytype.type = data
			uni.setStorageSync('mytype', data)
		},
	},
	actions: {

	},
	getters: {
		type: state => {
			state.type = uni.getStorageSync('mytype')
			return state.type;
		},
		money_now: state => {
			state.money_now = uni.getStorageSync('moneyNow')
			return state.money_now;
		},
		openid: state => {
			return uni.getStorageSync('getOpenid').openid;
		},
		mid: state => {
			if (uni.getStorageSync('getOpenid').mid) {
				state.mid = uni.getStorageSync('getOpenid').mid
			}
			return state.mid;
		},
		session_key: state => {
			return uni.getStorageSync('getOpenid').session_key;
		},
		token: state => {
			state.token=uni.getStorageSync('loginToken')
			// console.log('getters====>',uni.getStorageSync('loginToken'))
			return state.token;
		},
		hx_pass: state => {
			if (uni.getStorageSync('getOpenid').hx_pass) {
				state.hx_pass = uni.getStorageSync('getOpenid').hx_pass
			}
			return state.hx_pass;
		},
		hx_id: state => {
			if (uni.getStorageSync('getOpenid').hx_id) {
				state.hx_id = uni.getStorageSync('getOpenid').hx_id
			}
			return state.hx_id;
		},
		nickName: state => {
			state.nickName = uni.getStorageSync('userInfo').nickName
			return state.nickName;
		},
		avatar: state => {
			state.avatar = uni.getStorageSync('userInfo').avatarUrl
			return state.avatar;
		},
		sex: state => {
			state.sex = uni.getStorageSync('userInfo').gender,
			console.log('性别=================',state.sex)
			return state.sex;
		},

	}
})
export default store
